package com.ermace.robo.jumper.game.Player.AI;

import java.util.List;

import com.ermace.robo.jumper.game.Player.Robot;
import com.ermace.robo.jumper.game.Player.Robot.VerticalOrientation;

public class AI_Medium extends AI {

	private float decision;
	
	public AI_Medium(Robot robot, List<Robot> opponents) {
		super(robot, opponents);
	}
	
	@Override
	protected void calculateNextMove() {
		
		if (rand.nextDouble() < 0.05){
			switchTarget();
			return;
		}
		
		if (actionTime <= 0)
			decision = rand.nextFloat();
		
		boolean left = (getTarget().getPosition().getX() < robot.getPosition().getX());
		boolean up = (getTarget().getPosition().getY() <= robot.getPosition().getY());
		
		if (decision < 0.20 && robot.getVerticalOrientation() == VerticalOrientation.NONE)  // random jump ~20%
			robot.jump();
		if (decision < .4) { // something a little smarter ~40%
			if (left)
				robot.move(LEFT);
			else
				robot.move(RIGHT);
			if (up && decision < .25)
				robot.jump();
			
			if (actionTime <= 0)
				actionTime = rand.nextDouble() * 0.9 + 0.5;
		} else if (decision < .65) { // random move to left ~25%
			robot.move(LEFT);

			if (actionTime <= 0)
				actionTime = rand.nextDouble() + 0.35;
		} else if (decision < 0.9) {	// random move to right ~25%
			robot.move(RIGHT);
			
			if (actionTime <= 0)
				actionTime = rand.nextDouble() + 0.35;
		} else {		// random stop ~10%
			robot.stop();
			
			if (actionTime <= 0)
				actionTime = rand.nextDouble() * 0.2 + 0.5;
		}
	}
}
